package dicebot.tools.dice;

public class Add extends DiceExpression {

    public DiceExpression var1, var2;

    @Override
    public DiceExpression simplify() throws Exception {
        if (var1 instanceof Number && var2 instanceof Number) {
            return new Number(((Number) var1).value + ((Number) var2).value);
        } else {
            var1 = var1.simplify();
            var2 = var2.simplify();
            return this;
        }
    }

    public Add (DiceExpression var1, DiceExpression var2) {
        this.var1 = var1;
        this.var2 = var2;
    }

    @Override
    public String toString() {
        return var1.toString() + var2.toStringWithSign();
    }

    @Override
    public String toStringWithSign() {
        return var1.toStringWithSign() + var2.toStringWithSign();
    }
}
